Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get execution version from snapshot instead of state #6867

Merged
merged 4 commits into from
Jan 16, 2025

Conversation

janezpodhostnik
Copy link
Contributor

@janezpodhostnik janezpodhostnik commented Jan 10, 2025

work towards: #6507

Execution version was being read by calling a contract function on the service account. This meant it was read from the execution state. To reduce the impact on execution time it was put in the programs cache next to metering settings (execution effort weights, memory metering weights, memory limit).

The programs cache currently has a problem where it is invalidated on every block. This is due to the metering settings being inlined into the same register as the random beacon history. Since the random beacon history changes on every block, we have no choice but to also invalidate the metering settings. This in turn invalidates the entire programs cache. (programs cache entries contain programs and the execution effort it took to read them, which is derived from the metering settings).

The solution to the programs cache being invalidated on every block, is to move the metering settings to a separate, low/no traffic, account. However this solution does not work for the version beacon data, which would also need to be moved. Moving the version beacon data to a different account is much much harder as it has a lot of dependencies outside of execution.

In this PR I changed the FVM to instead read the version beacon data from protocol snapshot. We already read the Entropy source from the protocol snapshot, so I bundled these two things into a subset of the protocol snapshot that the FVM consumes for execution. This also prepares us for the future, where the execution version is going to be inside the dynamic protocol state (on the protocol snapshot).

@janezpodhostnik janezpodhostnik self-assigned this Jan 10, 2025
@codecov-commenter
Copy link

codecov-commenter commented Jan 10, 2025

Codecov Report

Attention: Patch coverage is 70.83333% with 14 lines in your changes missing coverage. Please review.

Project coverage is 34.48%. Comparing base (0d2b34f) to head (f097cb5).

Files with missing lines Patch % Lines
engine/execution/testutil/fixtures.go 76.00% 4 Missing and 2 partials ⚠️
engine/execution/computation/snapshot_provider.go 0.00% 4 Missing ⚠️
cmd/access/node_builder/access_node_builder.go 0.00% 1 Missing ⚠️
cmd/execution_builder.go 0.00% 1 Missing ⚠️
cmd/observer/node_builder/observer_builder.go 0.00% 1 Missing ⚠️
engine/testutil/nodes.go 0.00% 1 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (0d2b34f) and HEAD (f097cb5). Click for more details.

HEAD has 21 uploads less than BASE
Flag BASE (0d2b34f) HEAD (f097cb5)
unittests 30 9
Additional details and impacted files
@@             Coverage Diff             @@
##           master    #6867       +/-   ##
===========================================
- Coverage   41.11%   34.48%    -6.64%     
===========================================
  Files        2116      903     -1213     
  Lines      185737    78095   -107642     
===========================================
- Hits        76368    26928    -49440     
+ Misses     102952    49030    -53922     
+ Partials     6417     2137     -4280     
Flag Coverage Δ
unittests 34.48% <70.83%> (-6.64%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@janezpodhostnik janezpodhostnik force-pushed the janez/execution-version-from-snapshot branch 4 times, most recently from 168376a to 33bde51 Compare January 10, 2025 20:42
model/flow/snapshot_subset.go Outdated Show resolved Hide resolved
fvm/context.go Outdated Show resolved Hide resolved
engine/execution/computation/computer/computer.go Outdated Show resolved Hide resolved
engine/execution/computation/computer/computer.go Outdated Show resolved Hide resolved
fvm/executionParameters.go Show resolved Hide resolved
@janezpodhostnik janezpodhostnik marked this pull request as ready for review January 13, 2025 20:09
@janezpodhostnik janezpodhostnik requested a review from a team as a code owner January 13, 2025 20:09
@janezpodhostnik janezpodhostnik force-pushed the janez/execution-version-from-snapshot branch from 9c10352 to 8e753d9 Compare January 13, 2025 20:35
Copy link
Member

@zhangchiqing zhangchiqing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Looks good. Some minor suggestions.

model/flow/snapshot_subset.go Outdated Show resolved Hide resolved
return func(ctx Context) Context {
ctx.ReadVersionFromNodeVersionBeacon = enabled

ctx = WithEntropyProvider(snapshot)(ctx)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better to add some comments explain how it works for the two lines.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment is already on the WithEntropyProvider and on the snapshot.RandomSource I don't think it will help adding it here as well

move snapshot provider

move snapshot state provider

cleanup
@janezpodhostnik janezpodhostnik added this pull request to the merge queue Jan 16, 2025
Merged via the queue into master with commit 52d4461 Jan 16, 2025
56 checks passed
@janezpodhostnik janezpodhostnik deleted the janez/execution-version-from-snapshot branch January 16, 2025 10:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants